<div class="layui-form" lay-filter="layuiadmin-form-role" id="form">
	<div class="form-cont">
		<div class="layui-form-item verify" v-if="types==0">
		  <label class="layui-form-label">学校名称</label>
		  <div class="layui-input-block">
			  <input type="text" lay-verify="required" autocomplete="off" verify='requirel5' v-model="detail.school_name" placeholder="请输入学校名称" class="layui-input">
			  <span class="hint">学校名称必填</span>
			</div>
		</div>
		<div class="layui-form-item verify" v-else-if="types==1">
		  <label class="layui-form-label">院系名称</label>
		  <div class="layui-input-block">
			  <input type="text" lay-verify="required" autocomplete="off" verify='requirel5' v-model="detail.institute_name" placeholder="请输入院系名称" class="layui-input">
			  <span class="hint">院系名称必填</span>
			</div>
		</div>
		<div class="layui-form-item verify" v-else-if="types==11">
		  <label class="layui-form-label">宿舍名称</label>
		  <div class="layui-input-block">
			  <input type="text" lay-verify="required" autocomplete="off" verify='requirel5' v-model="detail.dormitory_name" placeholder="请输入宿舍名称" class="layui-input">
			  <span class="hint">宿舍名称必填</span>
			</div>
		</div>
		<div class="layui-form-item verify" v-else-if="types==2">
		  <label class="layui-form-label">专业名称</label>
		  <div class="layui-input-block">
			  <textarea type="text" class="layui-textarea" v-model="detail.majors_name" verify='require' placeholder="用 / 隔开可以一次添加多个专业"></textarea>
			  <span class="hint">专业名称必填</span>
			</div>
		</div>
		<div class="layui-form-item verify" v-else-if="types==21">
		  <label class="layui-form-label">楼栋名称</label>
		  <div class="layui-input-block">
			  <textarea type="text" class="layui-textarea" v-model="detail.tung_name" verify='require' placeholder="用 / 隔开可以一次添加多个楼栋"></textarea>
			  <span class="hint">楼栋名称必填</span>
			</div>
		</div>
		<div class="layui-form-item verify" v-else-if="types==31">
		  <label class="layui-form-label">房间名称</label>
		  <div class="layui-input-block">
			  <textarea type="text" class="layui-textarea" v-model="detail.room_name" verify='require' placeholder="用 / 隔开可以一次添加多个房间"></textarea>
			  <span class="hint">房间名称必填</span>
			</div>
		</div>
		<div class="layui-form-item verify" v-else-if="types==3">
		  <label class="layui-form-label">年级名称</label>
		  <div class="layui-input-block">
			  <textarea type="text" class="layui-textarea" v-model="detail.grade_name" verify='require' placeholder="用 / 隔开可以一次添加多个年级"></textarea>
			  <span class="hint">年级名称必填</span>
			</div>
		</div>
		<div class="layui-form-item verify" v-else-if="types==4">
		  <label class="layui-form-label">班级名称</label>
		  <div class="layui-input-block">
			  <textarea type="text" class="layui-textarea" v-model="detail.class_name" verify='require' placeholder="用 / 隔开可以一次添加多个班级"></textarea>
			  <span class="hint">班级名称必填</span>
			</div>
		</div>
	</div>
  
  <div class="form-btn" v-if="type!=3">
      <input type="button" value="保存" class="layui-btn" @click="submit">
  </div>
</div>

<script>
	layui.use(['form'], function(){
	  var $ = layui.$
	  ,form = layui.form;
	  var form=new Vue({
	  		el:'#form',
	  		data:{
	  			detail:{
					
				},
				old_detail:{},
				type:layui.admin.objData.type,
				types:layui.admin.objData.detail.types
	  		},
	  		created() {
				//初始化
	  			if(this.type==2) this.detail=layui.admin.objData.detail,this.old_detail=JSON.stringify(layui.admin.objData.detail);

	  		},
	  		methods:{
				submit:function(){
					if(layui.admin.form('#form')){
						if(this.type==2){   //编辑
							var url='schools/update',id='schools_id';
							if(this.types==1){
								url='schools/institute_update',id='institute_id';
							}else if(this.types==11){
								url='schools/dormitory_update',id='dormitory_id';
							}else if(this.types==2){
								url='schools/majors_update',id='majors_id';
							}else if(this.types==21){
								url='schools/tung_update',id='tung_id';
							}else if(this.types==31){
								url='schools/room_update',id='room_id';
							}else if(this.types==3){
								url='schools/grade_update',id='grade_id';
							}else if(this.types==4){
								url='schools/class_update',id='class_id';
							}
							var data=layui.admin.filter(this.detail,JSON.parse(this.old_detail),id);
							if(data){
								layui.admin.formapi(url,data);
							}
						}else{  //添加
							var url='schools/add';
							if(this.types==1){
								url='schools/institute_add';
								this.detail.school_id=layui.admin.objData.detail.id;
							}else if(this.types==11){
								url='schools/dormitory_add';
								this.detail.school_id=layui.admin.objData.detail.id;
							}else if(this.types==2){
								url='schools/majors_add';
								Object.assign(this.detail,layui.admin.objData.detail.id);
							}else if(this.types==21){
								url='schools/tung_add';
								this.detail.dormitory_id=layui.admin.objData.detail.id;
							}else if(this.types==31){
								url='schools/room_add';
								this.detail.tung_id=layui.admin.objData.detail.id;
							}else if(this.types==3){
								url='schools/grade_add';
								this.detail.majors_ids=layui.admin.objData.detail.id;
							}else if(this.types==4){
								url='schools/class_add';
								this.detail.grade_id=layui.admin.objData.detail.id;
							}
							layui.admin.formapi(url,this.detail);
						}
					}
				}
	  		}
	  	})
	});
</script>
